package com.ra.controller;


import com.ra.pojo.RespBean;
import com.ra.pojo.RespPageBean;
import com.ra.pojo.dto.ConditionDTO;
import com.ra.pojo.dto.TalkAdminDTO;
import com.ra.pojo.dto.TalkDTO;
import com.ra.service.ITalkService;
import com.ra.service.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 今晚几点睡_Ada
 * @since 2023-03-09
 */
@RestController
@Api(tags = "说说模块")
public class TalkController {
    //文件上传策略
    @Autowired
    private UploadService uploadService;
    @Autowired
    private ITalkService talkService;

    @ApiOperation(value = "上传说说图片")
    @ApiImplicitParam(name = "file", value = "说说图片", required = true, dataType = "MultipartFile")
    @PostMapping("/admin/talks/images")
    public RespBean<String> saveTalkImages(MultipartFile file) {
        return RespBean.success(uploadService.uploadFile(file, "talks/"));
    }

    @ApiOperation(value = "发布或修改说说")
    @PostMapping("/admin/talks")
    public RespBean<?> saveOrUpdateTalk(@Valid @RequestBody TalkDTO talkDTO) {
        talkService.saveOrUpdateTalk(talkDTO);
        return RespBean.success();
    }

    @ApiOperation(value = "删除说说")
    @DeleteMapping("/admin/talks")
    public RespBean<?> delTalks(@RequestBody List<Integer> talkIds) {
        talkService.delTalks(talkIds);
        return RespBean.success();
    }

    @ApiOperation(value = "查看后台说说")
    @GetMapping("/admin/talks")
    public RespBean<RespPageBean<TalkAdminDTO>> listTalksAdmin(ConditionDTO conditionDTO) {
        return RespBean.success(talkService.listTalksAdmin(conditionDTO));
    }

    @ApiOperation(value = "根据id查看后台说说")
    @ApiImplicitParam(name = "talkId", value = "说说id", required = true, dataType = "Integer")
    @GetMapping("/admin/talks/{talkId}")
    public RespBean<TalkAdminDTO> getTalkAdminById(@PathVariable("talkId") Integer talkId) {
        return RespBean.success(talkService.getTalkAdminById(talkId));
    }

}

